package com.sinven.util;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
    private static Configuration conf;
    private static SessionFactory sessionFactory;

    static {
        try {
            conf = new Configuration().configure();
            sessionFactory = conf.buildSessionFactory();
        } catch (HibernateException e) {
            e.printStackTrace();
            throw new RuntimeException("配置文件初始化错误", e);
        }
    }

    private HibernateUtil() {}

    public static Session getSession() {
        return sessionFactory.getCurrentSession();
    }
}
